- name: d8.extended-monitoring.cert-exporter.availability
  rules:

  - alert: D8CertExporterTargetDown
    expr: max by (job) (up{job="cert-exporter"} == 0)
    for: 1m
    labels:
      severity_level: "8"
      d8_module: extended-monitoring
      d8_component: cert-exporter
    annotations:
      plk_protocol_version: "1"
      plk_markup_format: "markdown"
      plk_create_group_if_not_exists__d8_cert_exporter_malfunctioning: "D8CertExporterMalfunctioning,prometheus=deckhouse,kubernetes=~kubernetes"
      plk_grouped_by__d8_cert_exporter_malfunctioning: "D8CertExporterMalfunctioning,prometheus=deckhouse,kubernetes=~kubernetes"
      plk_ignore_labels: "job"
      description: |
        Check the Pod status: `kubectl -n d8-monitoring get pod -l app=cert-exporter`

        Or check the Pod logs: `kubectl -n d8-monitoring logs -l app=cert-exporter -c cert-exporter`
      summary: Prometheus cannot scrape the cert-exporter metrics.

  - alert: D8CertExporterTargetAbsent
    expr: absent(up{job="cert-exporter"}) == 1
    for: 15m
    labels:
      severity_level: "8"
      d8_module: extended-monitoring
      d8_component: cert-exporter
    annotations:
      plk_protocol_version: "1"
      plk_markup_format: "markdown"
      plk_ignore_labels: "job"
      plk_create_group_if_not_exists__d8_cert_exporter_malfunctioning: "D8CertExporterMalfunctioning,prometheus=deckhouse,kubernetes=~kubernetes"
      plk_grouped_by__d8_cert_exporter_malfunctioning: "D8CertExporterMalfunctioning,prometheus=deckhouse,kubernetes=~kubernetes"
      description: |
        Check the Pod status: `kubectl -n d8-monitoring get pod -l app=cert-exporter`

        Or check the Pod logs: `kubectl -n d8-monitoring logs -l app=cert-exporter -c cert-exporter`
      summary: There is no `cert-exporter` target in Prometheus.

  - alert: D8CertExporterPodIsNotReady
    expr: min by (pod) (kube_pod_status_ready{condition="true", namespace="d8-monitoring", pod=~"cert-exporter-.*"}) != 1
    for: 30m
    labels:
      severity_level: "8"
      d8_module: extended-monitoring
      d8_component: cert-exporter
    annotations:
      plk_protocol_version: "1"
      plk_markup_format: "markdown"
      plk_labels_as_annotations: "pod"
      plk_create_group_if_not_exists__d8_cert_exporter_malfunctioning: "D8CertExporterMalfunctioning,prometheus=deckhouse,kubernetes=~kubernetes"
      plk_grouped_by__d8_cert_exporter_malfunctioning: "D8CertExporterMalfunctioning,prometheus=deckhouse,kubernetes=~kubernetes"
      summary: The cert-exporter Pod is NOT Ready.
      description: |
        The recommended course of action:
        1. Retrieve details of the Deployment: `kubectl -n d8-monitoring describe deploy cert-exporter`
        2. View the status of the Pod and try to figure out why it is not running: `kubectl -n d8-monitoring describe pod -l app=cert-exporter`

  - alert: D8CertExporterPodIsNotRunning
    expr: absent(kube_pod_status_phase{namespace="d8-monitoring",phase="Running",pod=~"cert-exporter-.*"})
    for: 30m
    labels:
      severity_level: "8"
      d8_module: extended-monitoring
      d8_component: cert-exporter
    annotations:
      plk_protocol_version: "1"
      plk_markup_format: "markdown"
      plk_create_group_if_not_exists__d8_cert_exporter_malfunctioning: "D8CertExporterMalfunctioning,prometheus=deckhouse,kubernetes=~kubernetes"
      plk_grouped_by__d8_cert_exporter_malfunctioning: "D8CertExporterMalfunctioning,prometheus=deckhouse,kubernetes=~kubernetes"
      summary: The cert-exporter Pod is NOT Running.
      description: |
        The recommended course of action:
        1. Retrieve details of the Deployment: `kubectl -n d8-monitoring describe deploy cert-exporter`
        2. View the status of the Pod and try to figure out why it is not running: `kubectl -n d8-monitoring describe pod -l app=cert-exporter`
